package com.control;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dao.DemoDao;

import hyl.core.MyFun;

@Controller
public class DemoControl {

	@Resource
	DemoDao daodemo;

	@RequestMapping("/demoform1.do")
	public String demoform1(String userid, Model model) {
		System.out.println(userid);
		return "login";
	}

	@RequestMapping("/demoform2.do")
	public String demoform2(Model model, HttpServletRequest req) {
		Object[] objs = new Object[4];
		objs[0] = req.getParameter("userid");
		objs[1] = req.getParameter("name");
		objs[2] = req.getParameter("contact");
		objs[3] = req.getParameter("pass");
		long i= daodemo.insertUser(objs);		
		return "edit.jsp";

	}
	
	@RequestMapping("/demolist3.do")	
	public String demolist3( HttpServletRequest req) {
		//如果需要查询参数 自己加	
		long cnt = daodemo.count(null);	
		List<Map<String, Object>> list = daodemo.select(null);	
		req.setAttribute("count", cnt );
		req.setAttribute("list", list );
		return "table.jsp";
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping("/demolist1.do")	
	@ResponseBody
	public List<List>  demolist1(HttpServletRequest req,String rs_index,String rs_size) {
		Map<String, Object> objs=new HashMap<String, Object>();
		objs.put("rs_index", MyFun.str2int(rs_index) ) ;		
		objs.put("rs_size", MyFun.str2int(rs_size) ) ;
		objs.put("where", req.getParameter("where")) ;
		List<List> list = daodemo.list(objs);
		return list;
	}

}
